/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gui;

import javax.microedition.lcdui.*;
import conexion.*;

/**
 * @author Renato
 */
public class Mapa extends Canvas implements CommandListener {
   private int width,height;
   private int anchor = Graphics.TOP | Graphics.LEFT;
   private Cine cine;
   private MenuCines mc;

    public Mapa(Cine cine, MenuCines mc) {
        try {
            this.cine = cine;
            this.mc = mc;
            width = getWidth();
            height = getHeight();
	    setCommandListener(this);
	    // Add the Exit command
	    addCommand(new Command("Regresar", Command.BACK, 1));
        } catch(Exception e) {
            e.printStackTrace();
        }
    } 
    public void limpiaPantalla(Graphics g){
        g.setColor( 255, 255, 255 );
        g.fillRect( 0, 0, width, height );
    }
    /**
     * paint
     */
    public void paint(Graphics g) {
        limpiaPantalla(g);
        g.setColor(0, 0, 0);
        try {
            g.drawImage(Conexion.ObtenerMapa(width, height, cine.getLatitud(), cine.getLongitud(), 1), 0, 0, anchor);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public Cine getCine() {
        return cine;
    }

    public void setCine(Cine cine) {
        this.cine = cine;
    }

    /**
     * Called when a key is pressed.
     */
    protected  void keyPressed(int keyCode) {
    }
    
    /**
     * Called when a key is released.
     */
    protected  void keyReleased(int keyCode) {
    }

    /**
     * Called when a key is repeated (held down).
     */
    protected  void keyRepeated(int keyCode) {
    }
    
    /**
     * Called when the pointer is dragged.
     */
    protected  void pointerDragged(int x, int y) {
    }

    /**
     * Called when the pointer is pressed.
     */
    protected  void pointerPressed(int x, int y) {
    }

    /**
     * Called when the pointer is released.
     */
    protected  void pointerReleased(int x, int y) {
    }
    
    /**
     * Called when action should be handled
     */
    public void commandAction(Command command, Displayable displayable) {
        if(command.getLabel().equals("Regresar")){
            mc.getMp().getMidlet().pantalla.setCurrent(mc);
        }
    }

}